import React, { Component } from 'react'
import { Route, Switch } from 'react-router-dom'

export default class Index extends Component {
    render() {
        const { router } = this.props
        return (
            <Switch>
                {
                    router.map((item, index) => {
                        return <Route path={item.path} render={(prop) => {
                            //    prop  路由信息
                            let Com = item.com
                            //  如果当前路由下有children才传递
                            if (item.children) {
                                return <Com { ...prop } children={item.children} />
                            } else {
                                return <Com { ...prop }/>
                            }
                        }} key={index} />
                    })
                }
            </Switch>
        )
    }
}
